<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单数据的自动收集</title>
</head>
<body>

<div id="test">
    <form action="/xxx" @submit.prevent="submit">
        <span>用户名: </span>
        <input type="text" v-model="username"><br>

        <span>密码: </span>
        <input type="password" v-model="password"><br>

        <span>性别: </span>
        <input type="radio" id="female" value="女" v-model="sex">
        <label for="female">女</label>
        <input type="radio" id="male" value="男" v-model="sex">
        <label for="male">男</label><br>

        <span>爱好: </span>
        <input type="checkbox" id="basket" value="basket" v-model="likes">
        <label for="basket">篮球</label>
        <input type="checkbox" id="foot" value="foot" v-model="likes">
        <label for="foot">足球</label>
        <input type="checkbox" id="pingpang" value="pingpang" v-model="likes">
        <label for="pingpang">乒乓</label><br>

        <span>城市: </span>
        <select v-model="cityId">
            <option value="">未选择</option>
            <!--value表示提交给后台的值-->
            <option :value="city.id" v-for="(city, index) in allCities" :key="city.id">{{city.name}}</option>
        </select><br>
        <span>介绍: </span>
        <textarea rows="10" v-model="info"></textarea><br><br>

        <input type="submit" value="注册">
    </form>
</div>

<script type="text/javascript" src="../js/vue.js"></script>
<script>
    new Vue({
        el: '#test',
        data: {
            username: '',
            password: '',
            sex: '',
            likes: [],
            allCities: [
                {id: 1, name: 'BJ'},
                {id: 2, name: 'GD'},
                {id: 3, name: 'SH'}
            ],
            cityId: 3,
            info: ''
        },
        methods: {
            submit() {
                console.log(this.username, this.password,
                    this.sex, this.likes, this.cityId, this.info)
            }
        }
    })

</script>
</body>
</html>